﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestUniformArray {
        [Fact]
        public void Test_New1 () {
            var uarry = new UniformArray ();

            Assert.Equal (0, uarry.Count);
        }

        /// <summary>
        /// Uniform変数を即値で指定するテスト
        /// </summary>
        [Fact]
        public void Test_Set_1 () {
            var uarry = new UniformArray ();
            var mat = new Matrix4x4 ();
            uarry.Add ("Hello", mat);

            Assert.Equal (1, uarry.Count);
        }


        /// <summary>
        /// Uniform変数をプロパティで指定するテスト
        /// </summary>
        [Fact]
        public void Test_Set_2 () {
            var uarry = new UniformArray ();
            var node = new Node ();
            uarry.Add ("Hello", node, () => node.Alpha);

            Assert.Equal (1, uarry.Count);
        }

        [Fact]
        public void Test_Get_1 () {
            var uarry = new UniformArray ();
            var mat = new Matrix4x4 ();

            uarry.Add ("Nakajima Hayate", mat);

            var takei = uarry.Get ("Nakajima Hayate");
            Assert.Equal ("Nakajima Hayate", takei.Name);
            Assert.Equal (mat, takei.Source);
            Assert.Equal (null, takei.PropertyName);
        }

        [Fact]
        public void Test_Get_2 () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Takei Junko", node, () => node.Alpha);

            var takei = uarry.Get ("Takei Junko");
            Assert.Equal ("Takei Junko", takei.Name);
            Assert.Equal (node, takei.Source);
            Assert.Equal ("Alpha", takei.PropertyName);
        }

        [Fact]
        public void Test_Indexer () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Yokokawa Kazumi", node, () => node.Alpha);

            var kazumi = uarry["Yokokawa Kazumi"];
            Assert.Equal ("Yokokawa Kazumi", kazumi.Name);
            Assert.Equal (node, kazumi.Source);
            Assert.Equal ("Alpha", kazumi.PropertyName);
        }

        [Fact]
        public void Test_Remove () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Wakamoto Tetsuko", node, () => node.Alpha);
            uarry.Remove ("Wakamoto Tetsuko");

            Assert.Equal (0, uarry.Count);
        }

        [Fact]
        public void Test_Enumerator () {
            var uarry = new UniformArray ();
            var tetsuko = new Node ();
            var kazumi = new Node ();
            var takei = new Node ();
            tetsuko.Alpha = 0.1f;
            kazumi.Alpha = 0.2f;
            takei.Alpha = 0.4f;

            uarry.Add ("Wakamoto Tetsuko", tetsuko, () => tetsuko.Alpha);
            uarry.Add ("Yokokawa Kazumi", kazumi, () => kazumi.Alpha);
            uarry.Add ("Takei Junko", takei, () => takei.Alpha);

            var sum = uarry.Sum (x => 1);

            Assert.Equal (3, sum);
        }

    }
}
